﻿using System;
using System.Collections;
using System.Collections.ObjectModel;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GraphBase.Interfaces;

namespace GraphBase
{
    public class Vertex : GraphObject, IVertex
    {
        List<Edge> m_incomingEdges = new List<Edge>();
        List<Edge> m_outgoingEdges = new List<Edge>();

        public ICollection IncomingEdges { get { return new ReadOnlyCollection<Edge>( m_incomingEdges ); } }
        public ICollection OutgoingEdges { get { return new ReadOnlyCollection<Edge>( m_outgoingEdges ); } }

        public IList<Edge> zzIncomingEdges { get { return m_incomingEdges; } }
        public IList<Edge> zzOutgoingEdges { get { return m_outgoingEdges; } }

        public void zzPerformRemove()
        {
            zzRemoveList(m_incomingEdges);
            zzRemoveList(m_outgoingEdges);
        }

        public void zzRemoveList(IEnumerable<Edge> edges)
        {
            //Clone the lists because edge remove actively updates
            //the list.
            List<Edge> edgeList = new List<Edge>(edges);
            foreach (Edge edge in edgeList)
            {
                ((EdgeCollection)Graph.Edges).Remove(edge);
            }
        }
    }
}
